// pages/buyMenberCard/buyMenberCard.js
var app = getApp()
Page({
  data: {
    current:0
  },
  onLoad: function (e) {
    var that = this;
    app.setVersion(that);
    const systemInfo = app.getSystemInfo();
    var x = systemInfo.windowWidth - 80;
    var y = systemInfo.windowHeight - 70;
    that.setData({
      x: x,
      y: y,
      showBtn:true
    })
  },
  onShow: function () {
    var that = this;
    app.setNavtitle('会员卡');
    if (!app.globalData.plumSession) {
      app.plumSessionCallback = plumSession => {
        that.requestCardList();
      }
    } else {
      that.requestCardList();
    }
  },
  requestCardList: function (cid) {
    var that = this;
    var data = {};
    data.map = 'applet_member_card_list';
    data.type = 2;
    app.setVersion(that);
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: app.globalData.requestUrl,
      data: data,
      success: function (res) {
        console.log(res.data);
        if (res.data.ec == 200) {
          that.setData({
            cardList: res.data.data
          })
        } else {
          that.setData({
            cardList: []
          })
        }
      },
      complete: function () {
        wx.hideLoading();
        wx.stopPullDownRefresh();
      }
    });
  },
  openMemberRecord:function(){
    var that =  this;
    wx.navigateTo({
      url: '/subpages/memberRecord/memberRecord',
    })
  },
  //得到当前swiper的current值
  getCurrent:function(e){
    var that = this;
    console.log(e.detail);
    that.setData({
      current: e.detail.current
    });
  },
  prevCard:function(){
    var that = this;
    var current = that.data.current;
    if (current==0){
      current = 1
    }else{
      current--;
    }
    that.setData({
      current: current
    });
  },
  nextCard: function () {
    var that = this;
    var current = that.data.current;
    if (current == 1) {
      current = 0
    }else{
      current++;
    }
    console.log(current)
    that.setData({
      current: current
    });
  },
  //打开支付订单页面
  openMemberCardPay:function(e){
    var that = this;
    var id = e.currentTarget.dataset.id;
    var cardName = e.currentTarget.dataset.name;
    var price = e.currentTarget.dataset.price;
    var type = e.currentTarget.dataset.type;
    console.log(id)
    console.log(cardName)
    console.log(price)
    wx.navigateTo({
      url: '/subpages/memberCardPay/memberCardPay?id=' + id + '&cardName=' + cardName+'&price='+price+'&type='+type,
    })
  },
  tocardDetail:function(e){
    var cardinfo = e.currentTarget.dataset.cardinfo;
    wx.setStorage({
      key: 'cardinfo',
      data: cardinfo,
      success:function(){
        wx.navigateTo({
          url: '/subpages/memcardDetail/memcardDetail'
        })
      }
    })
  }
})